package com.leen.admin.entity;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import java.util.List;


/**
 * @author 
 * 菜单权限表
 */
@Getter
@Setter
@Entity
@Table(name="sys_menu")
public class Menu implements Serializable {
    /**
     * 菜单ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "menu_id")
    private Integer menuId;

    /**
     * 菜单名称
     */
    @Column(name = "menu_name")
    private String menuName;

    /**
     * 父菜单ID
     */
    @Column(name = "parent_id")
    private Integer parentId;

    /**
     * 显示顺序
     */
    @Column(name = "order_num")
    private Integer orderNum;

    /**
     * 路由地址
     */
    @Column(name = "icon")
    private String icon;
    /**
     * 路由地址
     */
    @Column(name = "path")
    private String path;

    /**
     * 组件路径
     */
    @Column(name = "component")
    private String component;

    /**
     * 组件名称
     */
    @Column(name = "component_name")
    private String componentName;

    /**
     * 是否为外链（0是 1否）
     */
    @Column(name = "frame")
    private Integer frame;

    /**
     * 菜单类型（M目录 C菜单 F按钮）
     */
    @Column(name = "menu_type")
    private String menuType;

    /** 缓存 */
    @Column(name = "cache")
    private Boolean cache;


    /**
     * 菜单状态（0显示 1隐藏）
     */
    @Column(name = "hidden")
    private Boolean hidden;

    /**
     * 菜单状态（0正常 1停用）
     */
    @Column(name = "status")
    private Boolean status;

    /**
     * 权限标识
     */
    @Column(name = "perms")
    private String perms;


    /**
     * 创建者
     */
    @Column(name = "create_by")
    private String createBy;

    /**
     * 创建时间
     */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "create_time")
    private Date createTime;

    /**
     * 更新者
     */
    @Column(name = "update_by")
    private String updateBy;

    /**
     * 更新时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "update_time")
    private Date updateTime;

    @Override
    public boolean equals(Object o) {
        if (this == o){ return true;}
        if (o == null || getClass() != o.getClass()) {return false;}
        Menu menu = (Menu) o;
        return Objects.equals(menuId, menu.menuId) && Objects.equals(menuName, menu.menuName) && Objects.equals(parentId, menu.parentId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(menuId, menuName, parentId);
    }

    private static final long serialVersionUID = 1L;
}